import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/weather' },
  {
    path: '/weather',
    component: () => import('@/views/Weather'),
    children: [
      {
        path: '',
        component: () => import('@/views/Weather/LocalWeather')
      },
      {
        path: ':adcode',
        component: () => import('@/views/Weather/OtherWeather')
      }
    ]
  },
  { path: '*', component: () => import('@/views/NotFound') }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
